import trimesh
import numpy as np


mesh = trimesh.creation.icosphere()
ray_origins = np.array([[0, 0, -3],
                        [2, 2, -3]])
ray_directions = np.array([[0, 0, 1],
                           [0, 1, 0]])

locations, index_ray, index_tri = mesh.ray.intersects_location(
        ray_origins=ray_origins,
        ray_directions=ray_directions)

print('The rays hit the mesh at coordinates:\n', locations)
print('The rays with index: {} hit the triangles stored at mesh.faces[{}]'.format(index_ray, index_tri))


# ray_path_o = np.hstack((ray_origins,ray_origins + ray_directions*5.0))
# print(ray_path_o)


ray_path = np.hstack((ray_origins,ray_origins + ray_directions*5.0)).reshape(-1, 2, 3)
print(ray_path)

ray_visualize = trimesh.load_path(np.hstack((ray_origins,
                                             ray_origins + ray_directions*5.0)).reshape(-1, 2, 3))

print(ray_visualize)
#ray_visualize = trimesh.load_path(e.get_edge())

mesh.unmerge_vertices()
# make mesh white- ish1
mesh.visual.face_colors = [255, 255, 255, 255]
mesh.visual.face_colors[index_tri] = [255, 0, 0, 255]

scene = trimesh.Scene([mesh,
                       ray_visualize])

scene.show()